layui.define(['jquery','tool'],function (exports) {

    var $ = layui.jquery;
    var tool = layui.tool;

    var obj = {
        /**
         *
         * @param tragetId
         * @param selectOption
         * @param firstOption
         */
        createGoodType:function (tragetId,selectOption,firstOption) {
            $.ajax({
                url:'/back/category/getAllList'
                ,type:'post'
                ,data:null
                ,async:false
                ,dataType:'json'
                ,success:function(res){
                    if (res.code === return_200) {
                        var selectHtml = "";
                        if(!tool.isEmpty(firstOption)){
                            selectHtml += "<option value=''>" + firstOption + "</option>";
                        }
                        $("#" + tragetId).empty();
                        for (var i = 0; i < res.data.length; i++) {
                            if (selectOption && res.data[i].categoryCode == selectOption) {
                                selectHtml += "<option value=\"" + res.data[i].categoryCode + "\" selected>" + res.data[i].categoryName + "</option>";
                            } else {
                                selectHtml += "<option value=\"" + res.data[i].categoryCode + "\">" + res.data[i].categoryName + "</option>";
                            }
                        }
                        $("#" + tragetId).append(selectHtml);
                    } else {
                        console.log("初始化选择框失败");
                    }
                }
                ,error:function(){
                    console.log("初始化选择框异常");
                }
            });
        }
    };

    exports("auctionUtil",obj);
});